package com.jsgt.greekfire.dao.model

import android.os.Parcel
import android.os.Parcelable
import androidx.room.*
import org.jetbrains.annotations.NotNull

@Entity(
    tableName = "wallet",
    foreignKeys = [ForeignKey(
        entity = IdentityBean::class,
        parentColumns = ["id"],
        childColumns = ["identity_id"],
        onDelete = ForeignKey.CASCADE
    )],
    indices = [Index("identity_id")]
)
class WalletBean() : Parcelable {
    @PrimaryKey(autoGenerate = true)
    var id: Int = 0 //主键递增id

    @NotNull
    var key: String? = null

    @ColumnInfo(name = "identity_id")
    var identityId = 0
    var name: String? = null
    var address: String? = null
    var selection: Int = 1

    constructor(parcel: Parcel) : this() {
        id = parcel.readInt()
        key = parcel.readString()
        identityId = parcel.readInt()
        name = parcel.readString()
        address = parcel.readString()
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(id)
        parcel.writeString(key)
        parcel.writeInt(identityId)
        parcel.writeString(name)
        parcel.writeString(address)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<WalletBean> {
        override fun createFromParcel(parcel: Parcel): WalletBean {
            return WalletBean(parcel)
        }

        override fun newArray(size: Int): Array<WalletBean?> {
            return arrayOfNulls(size)
        }
    }

    data class Name(val id: String, val name: String)
}